package com.cxrj.zhsq.workorderManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.workorderManage.entity.PropertyResource;
import com.cxrj.zhsq.workorderManage.service.PropertyResourceService;

@RestController
public class PropertyResourceController {

	@Resource
	private PropertyResourceService propertyResourceService;

	/**
	 * 查询资源库
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyResources")
	@ResponseBody
	public Map<String, Object> selectPropertyResources(HttpServletRequest request, HttpServletResponse response) {
		return propertyResourceService.seletePropertyResourcePage(request, response);
	}

	/**
	 * 添加资源库
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyResource", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyResource(PropertyResource propertyResource, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyResource.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyResourceService.insertPropertyResource(propertyResource);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 删除资源库
	 * 
	 * @return
	 */
	@RequestMapping(value = "deletePropertyResource", method = RequestMethod.POST)
	public Map<String, Object> deletePropertyResource(String id, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyResourceService.deletePropertyResource(id);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询资源库
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyResourceById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectPropertyResourceById(String id, HttpServletRequest request) {
		return propertyResourceService.selectPropertyResourceById(id);
	}

	/**
	 * 根据pId查询资源库
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyResourceByPId", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectPropertyResourceByPId(String pId, HttpServletRequest request) {
		return propertyResourceService.selectPropertyResourceByPId(pId);
	}
}
